<?php
//$optiondomain = 'system';
require('system-config.php');
require_once(PRIVATEROOT . 'wp-includes/registration-functions.php');
validateToken($_POST['token'], 'createblog.php');
$user = get_userdatabylogin($_POST['admin']);
$blog_name = $_POST['blogname'];

if (!$user->user_admin) {
	
	if ( !slugAvailable($blog_name) )
		echo '<strong>ERROR</strong>: This blog name is already taken, please choose another one.<br/>';
	else if (!validateSlug($blog_name))
		echo '<strong>ERROR</strong>: This blog name is invalid, please choose another one.<br/>';
	else
	{
		$id = lyceum_create_blog_from_username($_POST['admin'], $blog_name);
		if (!$blog_id)
			echo '<strong>ERROR</strong>: Couldn&#8217;t create blog... please contact the webmaster<br/>';
		else
		{
			$url = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE blog='$id' AND option_name= 'home'");
			echo "<p>New blog: <a href=\"$url\">$url</a></p>";
		}
	}
}
else
	echo '<strong>A system administrator cannot be associated with a blog</strong>';
	
echo "<p><a href=\"blog-management.php\">return to Blog Management</a></p>";
?>